package com.csist.util;

import java.security.MessageDigest;

/**
 * @ClassName EncryptUtil
 * @Description 加密工具类
 * @Author 老陈
 * @Date 2024/4/24 21:53
 * @Version 1.0
 */
public class EncryptUtil {
	
	/**
	 * MD5加密
	 * @param pwd  待加密内容
	 * @return     加密后内容（32位长十六进制数据）
	 */
	public static String md5(String pwd) {  
		char md5String[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',  
                'A', 'B', 'C', 'D', 'E', 'F' };  
        try {  
            byte[] btInput = pwd.getBytes();  
               
            MessageDigest mdInst = MessageDigest.getInstance("MD5");  
               
            mdInst.update(btInput);  
               
            byte[] md = mdInst.digest();  
               
            int j = md.length;  
            char str[] = new char[j * 2];  
            int k = 0;  
            for (int i = 0; i < j; i++) {   
                byte byte0 = md[i];   
                str[k++] = md5String[byte0 >>> 4 & 0xf];   
                str[k++] = md5String[byte0 & 0xf];  
            }  
               
            return new String(str);//密文字符串返回
               
        } catch (Exception e) {  
            return null;  
        }  
    }  
}
